package com.bingo.controller;

import com.bingo.common.R;
import com.bingo.entity.dto.req.ReqForm;
import com.bingo.entity.dto.req.ReqPut;
import com.bingo.service.PutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Bingo
 * @version 1.0
 * @description 新苗投塘记录控制类
 * @date 2024/3/22 13:19
 */

@RestController
@RequestMapping("/put")
public class PutController {
    private PutService putService;
    @Autowired
    public void setPutService(PutService putService) {
        this.putService = putService;
    }


    //务必严谨，上报新苗投塘记录
    @PostMapping("/report")
    public R Put(@RequestBody ReqPut reqPut) {
        //对前端数据进行简易校验
        if (reqPut.getPoolNo() == null || reqPut.getQuantity() == null || reqPut.getWeight() == null || reqPut.getDate() == null  || reqPut.getIsUpdate() == null) {
            return R.error("参数错误或不全，请检查后重试！");
        }
        //补报日期不得超过15天
        if ((System.currentTimeMillis() - reqPut.getDate().getTime()) > 15 * 24 * 60 * 60 * 1000) {
            return R.error("补报日期不得超过15天！");
        }
        return putService.addPut(reqPut.getPoolNo(), reqPut.getQuantity(), reqPut.getWeight(),reqPut.getDate(),reqPut.getUserId(),reqPut.getIsUpdate());
    }

    //查询塘新苗投塘记录
    @PostMapping
    public R Put(@RequestBody ReqForm reqForm) {
        return R.success(putService.selectEveryDayPut(reqForm.getPoolNos(),reqForm.getDate()[0],reqForm.getDate()[1]));
    }

    //查询新苗投塘记录
    @PostMapping("/record")
    public R putRecord(@RequestBody ReqForm reqForm) {
        return R.success(putService.selectPutRecord(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1],reqForm.getUserId()));
    }

    //查询场的投苗记录
    @PostMapping("/site")
    public R sitePut(@RequestBody ReqForm reqForm) {
        return R.success(putService.selectSitePut(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1]));
    }


}
